import Vue from 'vue'
import Vuex from 'vuex'
import _find from 'lodash/find'
import _findKey from 'lodash/findKey'
import _isUndefined from 'lodash/isUndefined'
import _sortBy from 'lodash/sortBy'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {},
  mutations: {},
  actions: {},
  getters: {
    category: () => {
      return [
        {
          id: 1,
          name: '前刘海',
          zIndex: 9,
        },
        {
          id: 2,
          name: '后脑勺头发',
          zIndex: 1,
        },
        {
          id: 3,
          name: '眼睛',
          zIndex: 4,
        },
        {
          id: 4,
          name: '嘴巴',
          zIndex: 5,
        },
        {
          id: 5,
          name: '眉毛',
          zIndex: 6,
        },
        {
          id: 6,
          name: '身体',
          zIndex: 2,
        },
        {
          id: 7,
          name: '脸型',
          zIndex: 3,
        },
        {
          id: 8,
          name: '眼镜',
          zIndex: 8,
        },
        {
          id: 9,
          name: '胡子',
          zIndex: 7,
        },
        {
          id: 10,
          name: '头饰帽子',
          zIndex: 10,
        },
      ]
    },
    matter: () => {
      return [
        {
          id: 1,
          catId: 10,
          name: '时尚鸭舌帽',
          // image: require('@/static/matter/1.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/36443/7/14313/7302/5d3e52a1Ef17daa2c/9ba7ce322affbf39.png',
          selected: false,
          gender: 0,
        },
        {
          id: 2,
          catId: 10,
          name: '休闲渔夫帽',
          // image: require('@/static/matter/2.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/74284/18/5631/5513/5d3e52a0E50d78255/b4427cd93ecdd1d4.png',
          selected: false,
          gender: 0,
        },
        {
          id: 3,
          catId: 10,
          name: '甜美蝴蝶结2',
          // image: require('@/static/matter/3.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/58265/19/6139/3813/5d3e529fE0ba0f957/7b35ce46ce040bfc.png',
          selected: false,
          gender: 0,
        },
        {
          id: 4,
          catId: 10,
          name: '甜美蝴蝶结0',
          // image: require('@/static/matter/4.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/79751/31/5809/4304/5d3e529eEc86a4f64/a14607957f733b19.png',
          selected: false,
          gender: 0,
        },
        {
          id: 5,
          catId: 9,
          name: '可爱络腮胡',
          // image: require('@/static/matter/5.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/45209/8/6200/1778/5d3e529dE1c97a68d/661aa8a64c839a0d.png',
          selected: false,
          gender: 0,
        },
        {
          id: 6,
          catId: 8,
          name: '文艺粗眼镜',
          // image: require('@/static/matter/6.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/74063/15/5839/3390/5d3e529dEe63ec96b/54e5f4e08c7da138.png',
          selected: false,
          gender: 0,
        },
        {
          id: 7,
          catId: 8,
          name: '知性圆眼镜',
          // image: require('@/static/matter/7.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/76781/34/7053/4347/5d5268e2E3f128cd7/1005f927eef915c1.png',
          selected: false,
          gender: 0,
        },
        {
          id: 8,
          catId: 4,
          name: '大胖子',
          // image: require('@/static/matter/8.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/76175/17/5789/1716/5d3e529dE8895c72f/5f4a5d5fde9fb56f.png',
          selected: false,
          gender: 0,
        },
        {
          id: 9,
          catId: 4,
          name: '哦',
          // image: require('@/static/matter/9.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/40324/37/12652/1729/5d3e529dEf2491294/a0bdef1549ec2648.png',
          selected: false,
          gender: 0,
        },
        {
          id: 10,
          catId: 4,
          name: '哈哈大笑',
          // image: require('@/static/matter/10.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/65940/29/5751/2034/5d3e52a1E54bf63e3/83cec7d7cdc72f8c.png',
          selected: false,
          gender: 0,
        },
        {
          id: 11,
          catId: 4,
          name: '酷酷不笑',
          // image: require('@/static/matter/11.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/49119/15/6256/1393/5d3e52a1Ed4d1b771/53b5acfef6c3bff9.png',
          selected: false,
          gender: 0,
        },
        {
          id: 12,
          catId: 4,
          name: '普通的笑',
          // image: require('@/static/matter/11.png'),
          image: 'https://img14.360buyimg.com/imagetools/jfs/t1/66767/17/5754/1711/5d3e52a1Ecfa16183/fa34dece734d0118.png',
          selected: !false,
          gender: 0,
        },
        {
          id: 13,
          catId: 3,
          name: '高兴眯眯眼',
          // image: require('@/static/matter/13.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/43711/12/10442/2444/5d3e52a0E47c86e27/b29c5dee6228e5af.png',
          selected: false,
          gender: 0,
        },
        {
          id: 14,
          catId: 3,
          name: '低调豆豆眼',
          // image: require('@/static/matter/14.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/44933/16/6363/2719/5d3e52a0Efe21e63d/2e4822f5446ba671.png',
          selected: false,
          gender: 0,
        },
        {
          id: 15,
          catId: 3,
          name: '眯成一条缝',
          // image: require('@/static/matter/15.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/39254/25/12856/1652/5d3e52a0Ee56d3eb8/bf7e9f859a482731.png',
          selected: false,
          gender: 0,
        },
        {
          id: 16,
          catId: 3,
          name: '波波同款死鱼眼',
          // image: require('@/static/matter/16.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/81164/23/5725/2402/5d3e52a0E64a792c5/2efd91e99f95bab3.png',
          selected: false,
          gender: 0,
        },
        {
          id: 17,
          catId: 3,
          name: '丹凤眼',
          // image: require('@/static/matter/17.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/38678/25/12715/3430/5d3e52a0E0c3bbd2c/3a4b575e7723c0c3.png',
          selected: false,
          gender: 0,
        },
        {
          id: 18,
          catId: 3,
          name: '天真无邪',
          // image: require('@/static/matter/18.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/51872/30/6300/4438/5d3e52a0E09b2a964/1d844f7b7fe574de.png',
          selected: !false,
          gender: 0,
        },
        {
          id: 19,
          catId: 1,
          name: '碎刘海短',
          // image: require('@/static/matter/19.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/70237/38/5865/16613/5d3e52a0Ef0d1f18b/a870b86c8c380994.png',
          selected: false,
          gender: 0,
        },
        {
          id: 20,
          catId: 1,
          name: '常见刘海超短',
          // image: require('@/static/matter/20.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/58272/6/6183/17783/5d3e52a0E08227b18/08037a8814ea1124.png',
          selected: false,
          gender: 0,
        },
        {
          id: 21,
          catId: 1,
          name: '碎刘海',
          // image: require('@/static/matter/21.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/71842/3/5641/19091/5d3e52a0Eee9f9d25/855a602a14299d01.png',
          selected: false,
          gender: 0,
        },
        {
          id: 22,
          catId: 1,
          name: '常见刘海短',
          // image: require('@/static/matter/22.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/43341/9/10432/14173/5d3e52a0E52a5e17a/1c699c0b1d9ba407.png',
          selected: false,
          gender: 0,
        },
        {
          id: 23,
          catId: 1,
          name: '无刘海',
          // image: require('@/static/matter/23.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/50323/26/6210/13951/5d3e52a0Ea9e2ae99/98b9de6f6bd3c329.png',
          selected: false,
          gender: 0,
        },
        {
          id: 24,
          catId: 1,
          name: '中分短',
          // image: require('@/static/matter/24.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/84545/14/6271/18063/5d3e52a0Eb017462c/85835869ebd12166.png',
          selected: false,
          gender: 0,
        },
        {
          id: 25,
          catId: 1,
          name: '中分长',
          // image: require('@/static/matter/25.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/63583/31/5702/22012/5d3e529fEa60ceb21/1a1b878fbff30fe0.png',
          selected: false,
          gender: 0,
        },
        {
          id: 26,
          catId: 1,
          name: '三七分斜刘海',
          // image: require('@/static/matter/26.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/73473/1/5795/20789/5d3e529fEe4498fdf/23f54449d664b488.png',
          selected: false,
          gender: 0,
        },
        {
          id: 27,
          catId: 1,
          name: '眉上齐刘海',
          // image: require('@/static/matter/27.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/57247/6/6310/17793/5d3e529fE4c149fa7/009efd7f2a22a44f.png',
          selected: false,
          gender: 0,
        },
        {
          id: 28,
          catId: 1,
          name: '常见刘海',
          // image: require('@/static/matter/28.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/57888/38/6290/17889/5d3e529fEc0fcb957/b37cbe90a70dd51f.png',
          selected: !false,
          gender: 0,
        },
        {
          id: 29,
          catId: 5,
          name: '委屈粗眉',
          // image: require('@/static/matter/29.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/80662/25/5698/1883/5d3e529fEb24aaa57/e5f223771d3ede47.png',
          selected: false,
          gender: 0,
        },
        {
          id: 30,
          catId: 5,
          name: '上挑粗眉',
          // image: require('@/static/matter/30.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/54713/9/6292/1840/5d3e529fE99824f67/f7d7a7184dabb799.png',
          selected: false,
          gender: 0,
        },
        {
          id: 31,
          catId: 5,
          name: '平凡粗眉',
          // image: require('@/static/matter/31.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/76807/16/5721/2043/5d3e529fE133ebb13/7ddb1fbdf11ab9e6.png',
          selected: false,
          gender: 0,
        },
        {
          id: 32,
          catId: 5,
          name: '委屈细眉',
          // image: require('@/static/matter/32.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/47279/40/6320/1809/5d3e529fEeaf136a8/bc1e9ad3a907f296.png',
          selected: false,
          gender: 0,
        },
        {
          id: 33,
          catId: 5,
          name: '上挑细眉',
          // image: require('@/static/matter/33.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/70450/13/5789/1700/5d3e529fE42a2540b/d9c343ce4e72b21e.png',
          selected: false,
          gender: 0,
        },
        {
          id: 34,
          catId: 5,
          name: '平凡细眉',
          // image: require('@/static/matter/34.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/57635/24/6245/2194/5d3e529fE74ea0d9f/79867eb4fb2b1e49.png',
          selected: !false,
          gender: 0,
        },
        {
          id: 35,
          catId: 7,
          name: '脸',
          // image: require('@/static/matter/35.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/54358/30/6216/9879/5d3e529fEc5cc67d1/ec3595c90dcbff60.png',
          selected: !false,
          gender: 0,
        },
        {
          id: 36,
          catId: 6,
          name: '男生身子',
          // image: require('@/static/matter/36.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/84304/18/5788/21322/5d3e529fEf69e45a0/d0549b345c38a133.png',
          selected: false,
          gender: -1,
        },
        {
          id: 37,
          catId: 6,
          name: '女生身子',
          // image: require('@/static/matter/37.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/54290/37/6225/26800/5d3e529eEeb5c0b84/6befdccaa8a472c3.png',
          selected: !false,
          gender: -1,
        },
        {
          id: 38,
          catId: 2,
          name: '男孩子头',
          // image: require('@/static/matter/38.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/45023/37/6312/34853/5d3e529eEc2534010/c3a23a4d6db14e6e.png',
          selected: false,
          gender: 0,
        },
        {
          id: 39,
          catId: 2,
          name: '单麻花',
          // image: require('@/static/matter/39.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/40929/24/10394/46814/5d3e529eE44eab4a1/00155b5204379c52.png',
          selected: false,
          gender: 0,
        },
        {
          id: 40,
          catId: 2,
          name: '双麻花',
          // image: require('@/static/matter/40.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/74288/23/5867/46762/5d3e529eEe3330644/863307f884a72ff2.png',
          selected: false,
          gender: 0,
        },
        {
          id: 41,
          catId: 2,
          name: '披卷发',
          // image: require('@/static/matter/41.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/84381/34/6114/77199/5d3e529eE3c4ebbbd/48c7f4d3d62e6ad1.png',
          selected: false,
          gender: 0,
        },
        {
          id: 42,
          catId: 2,
          name: '齐肩卷',
          // image: require('@/static/matter/42.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/72501/33/5748/40212/5d3e529eEfb30bd06/9e924cf43760c8ae.png',
          selected: false,
          gender: 0,
        },
        {
          id: 43,
          catId: 2,
          name: '短卷发',
          // image: require('@/static/matter/43.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/74480/9/5768/47706/5d3e529eEf8831364/060a5f4ddda6aa35.png',
          selected: false,
          gender: 0,
        },
        {
          id: 44,
          catId: 2,
          name: '披直发',
          // image: require('@/static/matter/44.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/61471/37/5790/54384/5d3e529eE061b992d/eac4bcd5d01ebeae.png',
          selected: false,
          gender: 0,
        },
        {
          id: 45,
          catId: 2,
          name: '齐肩直',
          // image: require('@/static/matter/45.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/49223/24/6335/39387/5d3e529eE57bedb87/978bd2d204c67a00.png',
          selected: false,
          gender: 0,
        },
        {
          id: 46,
          catId: 2,
          name: '短发',
          // image: require('@/static/matter/46.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/41217/38/10445/41349/5d3e529eE5d3d9d43/e8d4717c7cd1bbd6.png',
          selected: false,
          gender: 0,
        },
        {
          id: 47,
          catId: 2,
          name: '单马尾',
          // image: require('@/static/matter/47.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/52500/21/6226/50561/5d3e529dE374cd97c/9b7baa13437249fe.png',
          selected: !false,
          gender: 0,
        },
        {
          id: 48,
          catId: 2,
          name: '圆头',
          // image: require('@/static/matter/48.png'),
          image: 'https://m.360buyimg.com/imagetools/jfs/t1/61689/32/5780/40061/5d3e529eE0b2e0d2e/8d239c7f49b01696.png',
          selected: false,
          gender: 0,
        },
      ]
    },
    tab: () => {
      // 刘海 后脑勺 眼睛 嘴巴 眉毛 配饰
      return [
        {
          id: 1,
          name: '刘海',
          catIds: [1],
          isShow: true,
        },
        {
          id: 2,
          name: '后脑勺',
          catIds: [2],
          isShow: true,
        },
        {
          id: 3,
          name: '眼睛',
          catIds: [3],
          isShow: true,
        },
        {
          id: 4,
          name: '嘴巴',
          catIds: [4],
          isShow: true,
        },
        {
          id: 5,
          name: '眉毛',
          catIds: [5],
          isShow: true,
        },
        {
          id: 6,
          name: '配饰',
          catIds: [8, 9, 10],
          isShow: true,
        },
        {
          id: 7,
          name: '身体',
          catIds: [6],
          isShow: false,
        },
        {
          id: 8,
          name: '脸型',
          catIds: [7],
          isShow: false,
        },
      ]
    },
    data_list: (state, getters) => {
      let data = []
      for (let i = 0, item, category, index; i < getters.matter.length; i++) {
        item = Object.assign({}, getters.matter[i])
        category = _find(getters.category, {id: item.catId})
        item.catName = category.name
        item.zIndex = category.zIndex
        index = _findKey(data, {catId: item.catId})
        if (_isUndefined(index)) {
          category = _find(getters.category, {id: item.catId})
          data.push({
            catId: item.catId,
            catName: category.name,
            zIndex: category.zIndex,
            catList: [item],
          })
        } else {
          data[index].catList.push(item)
        }
      }
      data = _sortBy(data, 'catId')

      let result = []
      for (let i = 0, item, list; i < getters.tab.length; i++) {
        item = Object.assign({}, getters.tab[i])
        list = []
        item.catIds.map(catId => {
          list = list.concat(_find(data, {catId}).catList)
          return catId
        })
        item.list = list
        result.push(item)
      }
      result = _sortBy(result, 'id')
      console.log(result)

      return result
    }
  },
})

export default store
